package com.linkgie.galaxyframework.shell.utils;

import org.jline.utils.AttributedString;

public class Acception {

	private boolean ok;

	private Object value;

	private AttributedString reason;

	private Acception(boolean ok, Object value, AttributedString reason) {
		this.ok = ok;
		this.value = value;
		this.reason = reason;
	}

	public static Acception accept(Object value) {
		return new Acception(true, value, null);
	}

	public static Acception reject(String reason) {
		return new Acception(false, null, new AttributedString(reason, ShellConsole.DEFAULT_SETTINGS.NORMAL_STYLE));
	}

	public static Acception reject(String reasonFormat, Object... args) {
		return new Acception(false, null, new AttributedString(String.format(reasonFormat, args), ShellConsole.DEFAULT_SETTINGS.NORMAL_STYLE));
	}
	
	public static Acception rejectInWarning(String reason) {
		return new Acception(false, null, new AttributedString(String.format(reason), ShellConsole.DEFAULT_SETTINGS.WARNING_STYLE));
	}

	public static Acception rejectInWarning(String reasonFormat, Object... args) {
		return new Acception(false, null, new AttributedString(String.format(reasonFormat, args), ShellConsole.DEFAULT_SETTINGS.WARNING_STYLE));
	}
	
	public static Acception rejectInError(String reason) {
		return new Acception(false, null, new AttributedString(String.format(reason), ShellConsole.DEFAULT_SETTINGS.ERROR_STYLE));
	}

	public static Acception rejectInError(String reasonFormat, Object... args) {
		return new Acception(false, null, new AttributedString(String.format(reasonFormat, args), ShellConsole.DEFAULT_SETTINGS.ERROR_STYLE));
	}

	public static void terminate(String reasonFormat, Object... args) throws InputTerminateException {
		Acception acception = reject(reasonFormat, args);
		throw new InputTerminateException(acception);
	}

	public static void terminateInWarning(String reasonFormat, Object... args) throws InputTerminateException {
		Acception acception = rejectInWarning(reasonFormat, args);
		throw new InputTerminateException(acception);
	}

	public static void terminateInError(String reasonFormat, Object... args) throws InputTerminateException {
		Acception acception = rejectInError(reasonFormat, args);
		throw new InputTerminateException(acception);
	}


	public boolean isOk() {
		return ok;
	}

	public AttributedString getReason() {
		return reason;
	}

	public Object getValue() {
		return value;
	}



}